package com.ase.mobile.config;

import org.springframework.amqp.core.*;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * @author gyhstart
 * @create 2021/3/15 - 12:02
 **/
@SpringBootConfiguration
public class RabbitmqConfig {
    /**
     *  配置一个工作模型队列
     */
    @Bean
    public Queue queueUser() {
        return new Queue("queue_user");
    }

    //===========================================================================================
    /**
     *  发布订阅模式
     *  声明两个队列
     */
    @Bean
    public Queue queueFanout1() {
        return new Queue("queue_fanout1");
    }
    @Bean
    public Queue queueFanout2() {
        return new Queue("queue_fanout2");
    }

    /**
     * 准备一个交换机
     * @return
     */
    @Bean
    public FanoutExchange exchangeFanout() {
        return new FanoutExchange("exchange_fanout");
    }

    /**
     * 将交换机和队列进行绑定
     * @return
     */
    @Bean
    public Binding bindingExchange1() {
        return BindingBuilder.bind(queueFanout1()).to(exchangeFanout());
    }
    @Bean
    public Binding bindingExchange2() {
        return BindingBuilder.bind(queueFanout2()).to(exchangeFanout());
    }
    //===========================================================================================

    // topic 模型

    /**
     * 通配符（或主题）模式
     * 符号 “#” 匹配一个或多个词，符号 “*” 仅匹配一个词
     */
    @Bean
    public Queue queueTopic1() {
        return new Queue("queue_topic1");
    }
    @Bean
    public Queue queueTopic2() {
        return new Queue("queue_topic2");
    }
    @Bean
    public TopicExchange exchangeTopic() {
        return new TopicExchange("exchange_topic");
    }
    //符号 “#” 匹配一个或多个词
    @Bean
    public Binding bindingTopic1() {
        return BindingBuilder.bind(queueTopic1()).to(exchangeTopic()).with("topic.#");
    }
    //，符号 “*” 仅匹配一个词
    @Bean
    public Binding bindingTopic2() {
        return BindingBuilder.bind(queueTopic2()).to(exchangeTopic()).with("topic.*");
    }

    //===========================================================================================
    //confirm机制

    // 测试confirm 机制，专门创建了一个队列
    @Bean
    public Queue queueConfirm() {
        return new Queue("queue_confirm");
    }


}
